//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "HaltonRsg.h"
using namespace Cephei::QL::Math::Randomnumbers;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Randomnumbers::CHaltonRsg::CHaltonRsg (boost::shared_ptr<QuantLib::HaltonRsg>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phHaltonRsg = NULL;
#endif
	_ppHaltonRsg = &childNative;
    
}
Cephei::QL::Math::Randomnumbers::CHaltonRsg::CHaltonRsg (QuantLib::HaltonRsg& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phHaltonRsg = NULL;
#endif
	_ppHaltonRsg = new boost::shared_ptr<QuantLib::HaltonRsg> (&childNative);
    
    _HaltonRsgOwner = owner;
    
}

Cephei::QL::Math::Randomnumbers::CHaltonRsg::CHaltonRsg (CHaltonRsg^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phHaltonRsg = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppHaltonRsg = new boost::shared_ptr<QuantLib::HaltonRsg> (copy->GetShared());
        
    }
}
Cephei::QL::Math::Randomnumbers::CHaltonRsg::CHaltonRsg (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phHaltonRsg = NULL;
#endif
	if (!t->IsSubclassOf(CHaltonRsg::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Randomnumbers::CHaltonRsg::CHaltonRsg (QuantLib::Handle<QuantLib::HaltonRsg>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phHaltonRsg = &childNative;
	_ppHaltonRsg = &static_cast<boost::shared_ptr<QuantLib::HaltonRsg>>(childNative.currentLink());
    
    _HaltonRsgOwner = owner;
}
Cephei::QL::Math::Randomnumbers::CHaltonRsg::CHaltonRsg (QuantLib::Handle<QuantLib::HaltonRsg> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phHaltonRsg = &childNative;
	_ppHaltonRsg = &static_cast<boost::shared_ptr<QuantLib::HaltonRsg>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Randomnumbers::CHaltonRsg::CHaltonRsg (QuantLib::HaltonRsg childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phHaltonRsg = NULL;
#endif
	_ppHaltonRsg = new boost::shared_ptr<QuantLib::HaltonRsg> (new QuantLib::HaltonRsg (childNative));
    
}
#endif

Cephei::QL::Math::Randomnumbers::CHaltonRsg::~CHaltonRsg ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppHaltonRsg != NULL)
    {
	    delete _ppHaltonRsg;
        _ppHaltonRsg = NULL;
    }
}
Cephei::QL::Math::Randomnumbers::CHaltonRsg::!CHaltonRsg ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppHaltonRsg != NULL)
    {
	    delete _ppHaltonRsg;
    }
}
QuantLib::HaltonRsg& Cephei::QL::Math::Randomnumbers::CHaltonRsg::GetReference ()
{
    if (_ppHaltonRsg == NULL) throw gcnew NativeNullException ();
	return **_ppHaltonRsg;
}
boost::shared_ptr<QuantLib::HaltonRsg>& Cephei::QL::Math::Randomnumbers::CHaltonRsg::GetShared ()
{
    if (_ppHaltonRsg == NULL) throw gcnew NativeNullException ();
	return *_ppHaltonRsg;
}
QuantLib::HaltonRsg* Cephei::QL::Math::Randomnumbers::CHaltonRsg::GetPointer ()
{
    if (_ppHaltonRsg == NULL) throw gcnew NativeNullException ();
	return &**_ppHaltonRsg;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::HaltonRsg>& Cephei::QL::Math::Randomnumbers::CHaltonRsg::GetHandle ()
{
	if (_phHaltonRsg == NULL)
	{
		_phHaltonRsg = new Handle<QuantLib::HaltonRsg> (*_ppHaltonRsg);
	}
	return *_phHaltonRsg;
}
#endif
bool Cephei::QL::Math::Randomnumbers::CHaltonRsg::HasNative () 
{
	return (_ppHaltonRsg != NULL);
}

UInt64 Cephei::QL::Math::Randomnumbers::CHaltonRsg::Dimension::get ()
{
    try
    {
    	QuantLib::Size _rv = (QuantLib::Size)(*_ppHaltonRsg)->dimension ( );   
        UInt64 _nrv = (UInt64)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

